package com.jandan.ui.client;

import com.gwtext.client.core.EventObject;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.layout.HorizontalLayout;
import com.gwtext.client.widgets.menu.BaseItem;
import com.gwtext.client.widgets.menu.Item;
import com.gwtext.client.widgets.menu.Menu;
import com.gwtext.client.widgets.menu.event.BaseItemListenerAdapter;
import com.jandan.ui.client.util.ClientUtil;

public class FunctionButtonsPanel extends Panel {
	private Button lessonButton;
	private Button strangeWordButton;
	private ILessonOperator lessonOperator;

	public FunctionButtonsPanel(ILessonOperator lessonOperate) {
		this.lessonOperator = lessonOperate;
		this.setLayout(new HorizontalLayout(5));
		createComponent();
//		this.setPaddings(60, 0, 0, 0);
	}

	private void createComponent() {
		
		
		lessonButton = new Button();
		lessonButton.setText("课程");
		

		Menu lessonMenu = new Menu();
		
		Item newLessonItem = new Item("新建课程");
		lessonMenu.addItem(newLessonItem);
//        cItem.setIconCls("生词本课程");   
  
//        Item strangeWordBookItem = new Item("生词本课程");   
//        cppItem.setIconCls("cpp-icon");   
  
//        subMenu.addItem(newLessonItem);   
//        subMenu.addItem(strangeWordBookItem);   
  
        //add menu item that has sub menu   
//        MenuItem lsItem = new MenuItem("新建课程", subMenu);   
        
//        lessonMenu.addItem(lsItem);

		newLessonItem.addListener(new BaseItemListenerAdapter() {
			@Override
			public void onClick(BaseItem item, EventObject e) {
				// TODO Auto-generated method stub
				LessonWindow window = new LessonWindow(lessonOperator);//ClientUtil.COMMON_LESSON);
				window.show(item.getId());
			}
		});
		
//		// setLessonItem.setIconCls("word-icon");
//		lessonMenu.addItem(setLessonItem);
//				
//		setLessonItem.addListener(new BaseItemListenerAdapter() {
//			@Override
//			public void onClick(BaseItem item, EventObject e) {
				// TODO Auto-generated method stub
//				MessageBox.alert("设置课程");
//				ChooseLessonWindow chooseLessonWindow = new ChooseLessonWindow();
//				
//				TreeMap<String,String> lessons = lessonOperator.getLessons();
//							
//				chooseLessonWindow.setTitle("选择要设置的课程");
//				
//				chooseLessonWindow.setLessons(lessons);
//				
//				chooseLessonWindow.show(item.getId());
//			}
//		});

		Item deleteLessonItem = new Item("删除课程");
		// deleteLessonItem.setIconCls("word-icon");
		lessonMenu.addItem(deleteLessonItem);

		deleteLessonItem.addListener(new BaseItemListenerAdapter() {
			@Override
			public void onClick(BaseItem item, EventObject e) {
				// TODO Auto-generated method stub
				ChooseLessonWindow chooseLessonWindow = new ChooseLessonWindow(lessonOperator,ClientUtil.DELETE_LESSON);
				chooseLessonWindow.show(item.getId());
			}
		});

		lessonButton.setMenu(lessonMenu);

		strangeWordButton = new Button();
		strangeWordButton.setText("生词本");

		Menu notebookMenu = new Menu();
		
		Item studyStrangeWordkItem = new Item("学习生词本");
		// newLessonItem.setIconCls("word-icon");
		notebookMenu.addItem(studyStrangeWordkItem);
		
		studyStrangeWordkItem.addListener(new BaseItemListenerAdapter(){

			@Override
			public void onClick(BaseItem item, EventObject e) {
				// TODO Auto-generated method stub
//				lessonOperator.studyStrangeWord();
			}
			
		});


		Item checkStrangeWordkItem = new Item("查看生词本");
		// newLessonItem.setIconCls("word-icon");
		notebookMenu.addItem(checkStrangeWordkItem);
		
		checkStrangeWordkItem.addListener(new BaseItemListenerAdapter(){

			@Override
			public void onClick(BaseItem item, EventObject e) {
				// TODO Auto-generated method stub
				lessonOperator.browseStrangeWord();
			}
			
		});
		
		
		Item addStrangeWordItem = new Item("添加生词");
		notebookMenu.addItem(addStrangeWordItem);
		addStrangeWordItem.addListener(new BaseItemListenerAdapter(){

			@Override
			public void onClick(BaseItem item, EventObject e) {
				// TODO Auto-generated method stub
//				MessageBox.alert("shit");
//				new StrangeWordWindow().show();
				lessonOperator.addStrangeWord();
			}
		});
		
		strangeWordButton.setMenu(notebookMenu);

		this.add(lessonButton);
		this.add(strangeWordButton);
	}
}
